Проблема: стандартные массивы для очереди могут привести к необходимости дорогостоящих операций сдвига элементов при удалении.
Решение: в книге Algorithms and Data Structures for OOP With C# автор предлагает реализовать очередь на основе связного списка, что позволяет эффективно добавлять элементы в конец и удалять с начала за O(1).
Пример кода:
public class Node<T> { public T Data; public Node<T> Next;
public Node(T data) { Data = data; Next = null; } }
public class QueueLinkedList<T> { private Node<T> front, rear;
public QueueLinkedList() { front = rear = null; }
public void Enqueue(T item) { var newNode = new Node<T>(item); if (rear == null) { front = rear = newNode; return; } rear.Next = newNode; rear = newNode; }
public T Dequeue() { if (front == null) throw new InvalidOperationException("Queue is empty.");
var data = front.Data; front = front.Next;
if (front == null) rear = null;
return data; } }
Преимущества: — Нет затрат на сдвиг элементов — Высокая производительность при операциях добавления и удаления — Универсальная реализация для любых типов данных
Проблема: стандартные массивы для очереди могут привести к необходимости дорогостоящих операций сдвига элементов при удалении.
Решение: в книге Algorithms and Data Structures for OOP With C# автор предлагает реализовать очередь на основе связного списка, что позволяет эффективно добавлять элементы в конец и удалять с начала за O(1).
Пример кода:
public class Node<T> { public T Data; public Node<T> Next;
public Node(T data) { Data = data; Next = null; } }
public class QueueLinkedList<T> { private Node<T> front, rear;
public QueueLinkedList() { front = rear = null; }
public void Enqueue(T item) { var newNode = new Node<T>(item); if (rear == null) { front = rear = newNode; return; } rear.Next = newNode; rear = newNode; }
public T Dequeue() { if (front == null) throw new InvalidOperationException("Queue is empty.");
var data = front.Data; front = front.Next;
if (front == null) rear = null;
return data; } }
Преимущества: — Нет затрат на сдвиг элементов — Высокая производительность при операциях добавления и удаления — Универсальная реализация для любых типов данных
Tata Power whose core business is to generate, transmit and distribute electricity has made no money to investors in the last one decade. That is a big blunder considering it is one of the largest power generation companies in the country. One of the reasons is the company's huge debt levels which stood at ₹43,559 crore at the end of March 2021 compared to the company’s market capitalisation of ₹44,447 crore.
Unlimited members in Telegram group now
Telegram has made it easier for its users to communicate, as it has introduced a feature that allows more than 200,000 users in a group chat. However, if the users in a group chat move past 200,000, it changes into "Broadcast Group", but the feature comes with a restriction. Groups with close to 200k members can be converted to a Broadcast Group that allows unlimited members. Only admins can post in Broadcast Groups, but everyone can read along and participate in group Voice Chats," Telegram added.